package cc.idoone.joddhttp.demo;

import jodd.http.HttpRequest;
import jodd.http.HttpResponse;

import java.util.HashMap;

/**
 * @author hemj
 * @version 2017/7/31
 */
public class PutRequestDemo {
    private static final String URL = "http://localhost:8088/joddhttp/test";

    public static void main(String[] args) {
        HttpRequest httpRequest = HttpRequest.put(URL);
        HttpResponse response = httpRequest.send();
        System.out.println(response);
        System.out.println(response.charset("UTF-8").bodyText());

        // 或者一步步构建
        HttpRequest request = new HttpRequest();
        request
                .method("PUT")
                .protocol("http")
                .host("localhost")
                .port(8088)
                .path("/joddhttp/test");
        System.out.println(request.send().charset("UTF-8").bodyText());

        // 带查询参数
        System.out.println(HttpRequest.put(URL + "?uid=1")
                .send().charset("UTF-8").bodyText());

        // 带查询参数
        HashMap<String, Object> formMap = new HashMap<>();
        formMap.put("form", "formValue");
        System.out.println(HttpRequest.put(URL + "?uid=1")
                .query("uname", "hemj")
                .form("formField1", "1")
                .form(formMap)
                .send().charset("UTF-8").bodyText());
    }
}
